import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ViewUIPlus from 'view-ui-plus'

import App from './App.vue'
import router from './router'
import 'view-ui-plus/dist/styles/viewuiplus.css'

import { UserInfoStore } from './stores/counter'
const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(ViewUIPlus)

router.beforeEach((to, from, next) => {
    let userInfoStore = UserInfoStore()
    if(userInfoStore.getState() == undefined || !userInfoStore.getState()){
      let cookie = sessionStorage.getItem("cookie")
      if(cookie != undefined && cookie != "undefined"){
        userInfo.setStateValue(JSON.parse(sessionStorage.getItem("cookie")))
      } 
    }
    // userInfoStore.setState(true)
    if (to.name !== 'login' && to.name !== 'logup' && !userInfoStore.getState()) next({ name: 'login' })
    else next()
  })

app.mount('#app')
